/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.smartercontext.contextmger.contextsphere;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author JuanPablo
 */
@Entity
@Table(name = "permissions", schema="contextsphere")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Permissions.findAll", query = "SELECT p FROM Permissions p"),
    @NamedQuery(name = "Permissions.findByIdPermission", query = "SELECT p FROM Permissions p WHERE p.idPermission = :idPermission"),
    @NamedQuery(name = "Permissions.findByPermission", query = "SELECT p FROM Permissions p WHERE p.permission = :permission")})
public class Permissions implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Column(name = "idPermission")
    private Integer idPermission;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 30)
    @Column(name = "permission")
    private String permission;
    @Size(max = 200)
    @Column(name = "description")
    private String description;
    @JoinTable(name = "user_permissions", schema="contextsphere", joinColumns = {
        @JoinColumn(name = "idPermission", referencedColumnName = "idPermission")}, inverseJoinColumns = {
        @JoinColumn(name = "username", referencedColumnName = "username")})
    @ManyToMany
    private List<Ctxtsphere> ctxtsphereList;

    public Permissions() {
    }

    public Permissions(Integer idPermission) {
        this.idPermission = idPermission;
    }

    public Permissions(Integer idPermission, String permission) {
        this.idPermission = idPermission;
        this.permission = permission;
    }

    public Integer getIdPermission() {
        return idPermission;
    }

    public void setIdPermission(Integer idPermission) {
        this.idPermission = idPermission;
    }

    public String getPermission() {
        return permission;
    }

    public void setPermission(String permission) {
        this.permission = permission;
    }
    
    
    public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	@XmlTransient
    public List<Ctxtsphere> getCtxtsphereList() {
        return ctxtsphereList;
    }

    public void setCtxtsphereList(List<Ctxtsphere> ctxtsphereList) {
        this.ctxtsphereList = ctxtsphereList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idPermission != null ? idPermission.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Permissions)) {
            return false;
        }
        Permissions other = (Permissions) object;
        if ((this.idPermission == null && other.idPermission != null) || (this.idPermission != null && !this.idPermission.equals(other.idPermission))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "org.smartercontext.contextmger.contextsphere.Permissions[ idPermission=" + idPermission + " ]";
    }
    
}
